home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Metrowerks Versions / C02 Sound Playing / P01 Sound Resource / SoundResource.c next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  1.8 KB  |  86 lines  |  [TEXT/MMCC]

  1. //____________________________________________________________
  2. //    SoundResource.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Sound.h>
  13.  
  14.  
  15. //____________________________________________________________
  16.  
  17. void   InitializeToolbox( void );
  18. OSErr  PlaySoundResourceSynch( SndChannelPtr, short );
  19.  
  20.  
  21. //____________________________________________________________
  22.  
  23. #define    rPoliceSiren       9000
  24.  
  25.  
  26. //____________________________________________________________
  27.  
  28. void  main( void )
  29. {
  30.    NumVersion  theSndMgrVers;
  31.    short       theResID;
  32.    OSErr       theError;
  33.    
  34.    InitializeToolbox();
  35.  
  36.    theSndMgrVers = SndSoundManagerVersion();   
  37.    if ( theSndMgrVers.majorRev < 3 )
  38.       ExitToShell();
  39.    
  40.    theResID = rPoliceSiren;
  41.    theError = PlaySoundResourceSynch( nil, theResID );   
  42.    if ( theError != noErr )
  43.       ExitToShell();
  44. }
  45.  
  46.  
  47. //____________________________________________________________
  48.  
  49. OSErr  PlaySoundResourceSynch( SndChannelPtr theChannel, short theResID )
  50. {
  51.    Handle  theHandle;
  52.    OSErr   theError;
  53.    
  54.    theHandle = GetResource( 'snd ', theResID );
  55.    
  56.    if ( theHandle == nil )
  57.    {   
  58.       return ( resProblem );
  59.    }
  60.    else
  61.    {
  62.       HLock( theHandle );
  63.          theError = SndPlay( theChannel, (SndListHandle)theHandle, false );
  64.       HUnlock( theHandle );
  65.    
  66.       ReleaseResource( theHandle );
  67.  
  68.       return ( theError );
  69.    }
  70. }
  71.  
  72.  
  73. //____________________________________________________________
  74.  
  75. void  InitializeToolbox( void )
  76. {
  77.    InitGraf( &qd.thePort );
  78.    InitFonts();
  79.    InitWindows();
  80.    InitMenus();
  81.    TEInit();
  82.    InitDialogs( 0L );
  83.    FlushEvents( everyEvent, 0 );
  84.    InitCursor();
  85. }
  86.